<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java方法重载与重写：深入理解面向对象编程的核心概念</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 8px 16px;
            font-size: 14px;
            color: #888;
            border-bottom: 1px solid #3e3e3e;
        }
        pre code {
            display: block;
            padding: 20px;
            overflow-x: auto;
            line-height: 1.6;
        }
        .keyword { color: #569cd6; }
        .string { color: #ce9178; }
        .comment { color: #6a9955; }
        .function { color: #dcdcaa; }
        .number { color: #b5cea8; }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.1rem;
            color: #667eea;
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 16px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        .table-custom {
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
        }
        .table-custom th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: 600;
            padding: 16px 24px;
            text-align: left;
        }
        .table-custom td {
            padding: 16px 24px;
            border-bottom: 1px solid #e5e7eb;
        }
        .table-custom tr:last-child td {
            border-bottom: none;
        }
        .table-custom tr:hover {
            background-color: #f9fafb;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-24 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                Java方法重载与重写
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                深入理解面向对象编程的核心概念，掌握静态多态与动态多态的精髓
            </p>
            <div class="mt-10 flex justify-center space-x-8">
                <div class="text-center">
                    <i class="fas fa-layer-group text-3xl mb-2"></i>
                    <p class="text-sm opacity-80">方法重载</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-code-branch text-3xl mb-2"></i>
                    <p class="text-sm opacity-80">方法重写</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-shapes text-3xl mb-2"></i>
                    <p class="text-sm opacity-80">多态性</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-lg p-10">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">方</span>法重载（Overloading）和方法重写（Overriding）是Java中两个重要的概念，它们在面向对象编程中起着关键作用。理解它们的区别有助于更好地设计和实现类的行为。这两个概念虽然名称相似，但在实现机制、应用场景和设计目的上有着本质的区别。
                </p>
            </div>
        </div>
    </section>

    <!-- Method Overloading Section -->
    <section class="py-16 px-6 bg-white">
        <div class="max-w-6xl mx-auto">
            <div class="mb-12">
                <h2 class="text-4xl font-bold mb-4 gradient-text">1. 方法重载 (Overloading)</h2>
                <p class="text-lg text-gray-600 leading-relaxed max-w-4xl">
                    方法重载是指在同一个类中，允许定义多个同名但参数列表不同的方法。参数列表的不同可以是参数的类型、数量或顺序不同。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card-hover bg-gray-50 rounded-xl p-8">
                    <div class="feature-icon">
                        <i class="fas fa-clone"></i>
                    </div>
                    <h3 class="text-2xl font-semibold mb-4">核心特点</h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>同一类中：</strong>重载的方法在同一类内定义，或在子类中重写父类的重载方法。
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>参数列表不同：</strong>方法名称相同，但参数的类型、数量或顺序必须不同。
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>返回类型不影响重载：</strong>即使返回类型不同，如果参数列表没有变化，也不能算作重载。
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>编译时多态：</strong>重载是编译时多态（静态多态），方法的选择在编译时决定。
                            </div>
                        </li>
                    </ul>
                </div>

                <div class="card-hover">
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-code mr-2"></i>Calculator.java
                        </div>
                        <pre><code><span class="keyword">class</span> <span class="function">Calculator</span> {
    <span class="keyword">public int</span> <span class="function">add</span>(<span class="keyword">int</span> a, <span class="keyword">int</span> b) {
        <span class="keyword">return</span> a + b;
    }

    <span class="keyword">public double</span> <span class="function">add</span>(<span class="keyword">double</span> a, <span class="keyword">double</span> b) {
        <span class="keyword">return</span> a + b;
    }

    <span class="keyword">public int</span> <span class="function">add</span>(<span class="keyword">int</span> a, <span class="keyword">int</span> b, <span class="keyword">int</span> c) {
        <span class="keyword">return</span> a + b + c;
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Method Overriding Section -->
    <section class="py-16 px-6 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <div class="mb-12">
                <h2 class="text-4xl font-bold mb-4 gradient-text">2. 方法重写 (Overriding)</h2>
                <p class="text-lg text-gray-600 leading-relaxed max-w-4xl">
                    方法重写是指在子类中重新定义父类中已经存在的方法，方法的名称、参数列表及返回类型必须完全相同。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card-hover">
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-code mr-2"></i>Animal.java
                        </div>
                        <pre><code><span class="keyword">class</span> <span class="function">Animal</span> {
    <span class="keyword">public void</span> <span class="function">sound</span>() {
        System.out.println(<span class="string">"动物发出声音"</span>);
    }
}

<span class="keyword">class</span> <span class="function">Dog</span> <span class="keyword">extends</span> Animal {
    <span class="comment">@Override</span>
    <span class="keyword">public void</span> <span class="function">sound</span>() {
        System.out.println(<span class="string">"狗叫"</span>);
    }
}</code></pre>
                    </div>
                </div>

                <div class="card-hover bg-white rounded-xl p-8">
                    <div class="feature-icon">
                        <i class="fas fa-sync-alt"></i>
                    </div>
                    <h3 class="text-2xl font-semibold mb-4">核心特点</h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>子类中重写父类的方法：</strong>重写发生在子类和父类之间。
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>方法签名完全相同：</strong>名称、参数列表和返回类型都必须一致。
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>动态多态：</strong>重写是动态多态（运行时多态），方法的选择在运行时决定。
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <strong>@Override 注解：</strong>使用 @Override 注解可以提高可读性，并在编译时检查重写是否符合规范。
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section class="py-16 px-6 bg-white">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold mb-8 text-center">概念关系图</h2>
            <div class="bg-gray-50 rounded-xl p-8">
                <div class="mermaid">
                    graph TD
                        A[Java方法机制] --> B[方法重载 Overloading]
                        A --> C[方法